package zisu.algorithm.algorithm.LinkedList;

import zisu.algorithm.algorithm.Stack.Stack;

/**
 * @Author: 蔡翔
 * @Date: 2019/12/5 10:51
 * @Version 1.0
 */
public class LinkListStack<E> implements Stack<E> {
    private LinkedList<E> list;

    public LinkListStack(){
        list = new LinkedList<>();
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public int getCapacity() {
        return list.getSize();
    }


    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }

    @Override
    public void push(E e) {
        list.addFirst(e);
    }

    @Override
    public E pop() {
        return list.removeFirst();
    }

    @Override
    public E peek() {
        return list.getFirst();
    }

    @Override
    public String toString() {
        StringBuilder str = new StringBuilder();
        str.append("Stack : top [ ");
        str.append(list);
        str.append(" tail ]");
        return str.toString();
    }

    public static void main(String[] args) {
        LinkListStack<Integer> linkedList = new LinkListStack<>();
        for(int i=0;i<5;i++){
            linkedList.push(i);
            System.out.println(linkedList);
        }
        linkedList.pop();
        System.out.println(linkedList);
        System.out.println("peek:"+ linkedList.peek());

        System.out.println(linkedList);

    }
}